package fq.status;

import org.apache.flink.api.common.functions.RichFlatMapFunction;
import org.apache.flink.api.common.state.ValueState;
import org.apache.flink.api.common.state.ValueStateDescriptor;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.runtime.state.filesystem.FsStateBackend;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;
 
public class CountingExample {
    public static void main(String[] args) throws Exception {
        // 设置流执行环境
        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
//        env.setStateBackend(new FsStateBackend("file:///Users/fang/IdeaProjects/know_how_know_why/khkw/store")); // 设置状态后端和检查点目录
//        env.setStateBackend(new RocksDBStateBackend("file:///tmp/flink-rocksdb", true));
        env.enableCheckpointing(10000); // 启用检查点，每10秒一次
 
        // 创建测试数据流
        DataStream<String> text = env.fromElements("apple", "banana", "apple", "orange", "banana", "apple");

        text.keyBy(e->e)
                .map(new MyMapFunction())
                .print();

        // 执行程序
        env.execute("Counting Example");
    }
}